package com.hyacinth.lotterysystem.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hyacinth.lotterysystem.common.pojo.CommonResult;
import com.hyacinth.lotterysystem.dto.req.CreatePrizeReq;
import com.hyacinth.lotterysystem.dto.req.PrizeListReq;
import com.hyacinth.lotterysystem.dto.resp.PrizeListResp;
import com.hyacinth.lotterysystem.dto.resp.PrizeNameListResp;
import com.hyacinth.lotterysystem.service.PictureService;
import com.hyacinth.lotterysystem.service.PrizeService;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/prize")
public class PrizeController {
    private static final Logger logger = LoggerFactory.getLogger(PrizeController.class);
    @Resource
    private PictureService pictureService;
    @Resource
    private PrizeService prizeService;

    @PostMapping("/pic/upload")
    public CommonResult<String> pictureUpload(MultipartFile file) {
        return CommonResult.success(pictureService.savePicture(file));
    }

    @PostMapping("/create")
    public CommonResult<Long> createPrize(@Validated @RequestPart("param") CreatePrizeReq param,
                                          @RequestPart("prizePic") MultipartFile file) {
        logger.info("创建奖品 -> CreatePrizeReq: {} , MultipartFile: {} ", param, file.getOriginalFilename());
        return CommonResult.success(prizeService.createPrize(param, file));
    }

    @GetMapping("/list")
    public CommonResult<IPage<PrizeListResp>> selectPrizeList(PrizeListReq param) {
        logger.info("查询奖品列表 -> PrizeListReq: {}", param);
        return CommonResult.success(prizeService.selectPrizeList(param));
    }

    @GetMapping("/nameList")
    public CommonResult<PrizeNameListResp> selectPrizeNameList() {
        return CommonResult.success(prizeService.selectPrizeNameList());
    }
}
